import 'package:flutter/material.dart';

import '../../../base/base_model.dart';
import '../../../http/user_dao.dart';
import '../../../resources.dart';

/// created by hcl
/// on 2025/2/4
/// ChangePhoneModel
/// desc
class ChangePasswordModel extends BaseModel {
  TextEditingController oldPasswordController = TextEditingController();
  FocusNode oldPasswordFocusNode = FocusNode();
  TextEditingController newPasswordController = TextEditingController();
  FocusNode newPasswordFocusNode = FocusNode();
  TextEditingController confirmPasswordController = TextEditingController();
  FocusNode confirmPasswordFocusNode = FocusNode();

  @override
  initData() {}

  change({bool isInit = false}) {
    if (oldPasswordController.text.isEmpty) {
      showToast(word.please_enter_old_password);
      return;
    }

    if (oldPasswordController.text != GSpUtils.get(GSpUtils.password)) {
      showToast(word.please_enter_right_password);
      return;
    }
    if (newPasswordController.text.isEmpty) {
      showToast(word.please_enter_new_password);
      return;
    }
    if (confirmPasswordController.text.isEmpty) {
      showToast(word.please_enter_confirm_password);
      return;
    }
    if (newPasswordController.text != confirmPasswordController.text) {
      showToast(word.password_different);
      return;
    }
    if (newPasswordController.text == oldPasswordController.text) {
      showToast(word.password_same);
      return;
    }
    Toast.showLoading();
    Future.delayed(const Duration(seconds: 2), () {
      Toast.close();
    });
  }
}
